package com.example.exam.MeunFrgment;


import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;

import com.example.exam.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * A simple {@link Fragment} subclass.
 */
public class PowerFragment extends Fragment {
    @BindView(R.id.power_button)
    Button powerButton;
    private View view;
    public PowerFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_power, container, false);
        ButterKnife.bind(this,view);
        return view;
    }

    @OnClick(R.id.power_button)
    public void onViewClicked() {
            String permissions = Manifest.permission.READ_CALENDAR;
            power(1,permissions);
    }
    private void power(int id,String permissions){
        //检测权限
        int checkCallPhonePermission   = ContextCompat.checkSelfPermission(getContext(),permissions);
        if(checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
            //弹出对话框
            ActivityCompat.requestPermissions(getActivity(), new String[]{permissions}, 1);
        }
    }
}
